<template>
  <a-spin :spinning="spinning">
    <page-header-wrapper>
      <application-search
        :filterFields="['CityRfyResult']"
        @search="handleSearch"
        @reset="handleReset"
        :moreHandles="[
          { name: '通过所选', btType: 'success', data: selectedRowKeys },
          { name: '不通过所选', btType: 'danger', data: selectedRowKeys },
          { name: '通过全部', btType: 'info', data: selectedRowKeysall },
        ]"
      >
      </application-search>
      <a-card :bordered="false">
        <s-table
          :scroll="{ x: 2700 }"
          ref="table"
          size="default"
          rowKey="ID"
          :columns="columns"
          :data="loadData"
          :rowSelection="{ fixed: true, selectedRowKeys: selectedRowKeys, onChange: handleRowSelectionChange }"
          :pagination="{ showTotal: (total) => `共 ${total} 条` }"
        >
          <!-- :options="[
                { value: '', label: '全部' },
                { value: '符合', label: '符合' },
                { value: '不符合', label: '不符合' },
                { value: '未审批', label: '未审批' },
              ]" -->
          <div slot="tabAction">
            <buttonSelect class="m-l-10" v-model="typeSelect" @change="handleButtonSelectChange"></buttonSelect>
          </div>
          <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
          <div slot="action" slot-scope="text, record">
            <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
            <y-button type="link" @click="handleAudit(record.ID)">审批</y-button>
          </div>
        </s-table>
      </a-card>
    </page-header-wrapper>
  </a-spin>
</template>

<script>
import { STable, Ellipsis, buttonSelect } from '@/components'
import applicationSearch from './application.vue'
import { getProposerList } from '@/api/common'
import moment from 'moment'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    buttonSelect,
    applicationSearch,
  },
  computed: {
    textColor() {
      return function (text) {
        const classMap = new Map([
          ['符合', 'text-success'],
          ['不符合', 'text-error'],
          ['未审核', 'text-warning'],
          ['未审批', 'text-warning'],
        ])
        return classMap.get(text)
      }
    },
  },
  data() {
    this.$eventBus.$on('leaderAuditRefresh', () => {
      this.$refs.table.refresh()
    })
    return {
      spinning: false, // 加载
      typeSelect: '',
      queryParam: {
        UserID: this.$store.getters.userid,
        Mode: 'BossNewRfy',
        strContent: { CityRfyResult: '未审批' },
      },
      // selectedRowKeysall: [],
      selectedRowKeysall: (parameter) => {
        const requestParameters = Object.assign(
          {},
          {
            pageIndex: 1,
            pageSize: 99999,
          },
          this.queryParam
        )
        requestParameters.strContent.CityRfyResult = '未审批'
        return getProposerList(requestParameters).then((res) => {
          this.total = res.count
          return res
        })
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请编号',
          align: 'center',
          dataIndex: 'ApplyNo',
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          dataIndex: 'IDCard',
        },
        {
          title: '保障类型',
          align: 'center',
          dataIndex: 'ApplyClass',
        },
        {
          title: '区县',
          align: 'center',
          dataIndex: 'RegionName',
          customRender: (text) => {
            return <ellipsis length={16}>{text}</ellipsis>
          },
        },
        {
          title: '市审核结果',
          align: 'center',
          dataIndex: 'CityVfyResult',
          customRender: (text) => <span class={this.textColor(text || '未审核')}>{text || '未审核'}</span>,
        },
        // {
        //   title: '审批结果',
        //   align: 'center',
        //   dataIndex: 'CityRfyResult',
        //   customRender: (text) => <span class={this.textColor(text || '未审批')}>{text || '未审批'}</span>
        // },
        {
          title: '信息',
          align: 'center',
          customRender: (text, record) => {
            const days = moment().diff(moment(record.ProcessDate), 'days')
            if (days <= 16) {
              return <span class="text-success">离过期还剩{16 - days}天</span>
            } else {
              return <span class="text-error">已过期{days - 16}天</span>
            }
          },
        },
        {
          title: '配租方式',
          align: 'center',
          dataIndex: 'CityVfyAssign',
        },
        {
          title: '街道办事处',
          align: 'center',
          dataIndex: 'TownshipName',
          customRender: (text) => {
            return <ellipsis length={16}>{text}</ellipsis>
          },
        },
        {
          title: '核定保障人数',
          align: 'center',
          dataIndex: 'CityVfyNumber',
        },
        {
          title: '市级审核人',
          align: 'center',
          dataIndex: 'CityVfyAgent',
        },
        {
          title: '审核日期',
          align: 'center',
          dataIndex: 'CityVfyDate',
          customRender: (text) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
        },
        {
          title: '操作',
          align: 'center',
          width: '180px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        requestParameters.strContent.CityRfyResult = '未审批'
        return getProposerList(requestParameters).then((res) => {
          this.total = res.count
          return res
        })
      },
      total: 0,
      selectedRowKeys: [],
    }
  },

  methods: {
    handleRowSelectionChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    // selectedRowKeysall: (parameter) => {
    //   const requestParameters = Object.assign(
    //     {},
    //     {
    //       pageIndex: 1,
    //       pageSize: 99999,
    //     },
    //     this.queryParam
    //   )
    //   requestParameters.strContent.CityRfyResult = this.typeSelect
    //   return getProposerList(requestParameters).then((res) => {
    //     return res
    //   })
    // },
    handleSearch(values) {
      this.queryParam.strContent = values
      this.$refs.table.refresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.typeSelect = '未审批'
      this.$refs.table.refresh(true)
    },
    handleButtonSelectChange() {
      this.$refs.table.refresh(true)
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'cityComplexInquireDetail',
        params: {
          id,
        },
      })
    },
    handleAudit(id) {
      this.$router.push({
        name: 'leaderNewReviewManageAudit',
        params: {
          id,
          type: 'leader',
        },
      })
    },
  },
}
</script>
<style lang="less" scoped></style>
